<style scoped>
    .title{
        margin-bottom:10px;
    }
</style>
<template>
    <div class="notice-list-page">

        <el-form :inline="true" :model="formInline" :rules="rules" ref="formInline" class="demo-form-inline" style="margin-bottom:20px;border-bottom:1px solid #ccc;">
            <p class="title">
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" :disabled="isClick" @click="saveShipReqInfo('formInline')">保存</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" :disabled="isClick" @click="commitShipReqInfo('formInline')">提交</el-button>
            </p>
            <p>
                <el-form-item label="送货通知单号" class="selectMB10" :label-width="labelWidth100">
                    <el-input  v-model="formInline.shipRequestNo" disabled></el-input>
                </el-form-item>
                <el-form-item label="制单人" class="selectMB10" :label-width="labelWidth">
                    <el-input  v-model="formInline.shipRequestUserName" disabled></el-input>
                </el-form-item>
                <el-form-item label="制单日期" prop="createTime" class="selectMB10" :label-width="labelWidth">
                    <el-input  v-model="formInline.createTime" disabled></el-input>
                </el-form-item>
            </p>
            <p>
                <!--库房地和直发地填入-->
                <el-form-item label="收货地简称" class="selectMB10" :label-width="labelWidth">
                    <el-input  v-model="formInline.shortName" disabled></el-input>
                </el-form-item>
                <el-form-item class="selectMB10">
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="selectStoreRoom()">选择收货库房</el-button>
                </el-form-item>
                <el-form-item class="selectMB10">
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="selectShipAddress()">选择直发地址</el-button>
                </el-form-item>
                <el-form-item class="selectMB10">
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="addShipAddress()">新增直发地址</el-button>
                </el-form-item>
            </p>
            <p>
                <el-form-item label="详细地址" class="selectMB10" :label-width="labelWidth">
                    <el-input  v-model="formInline.adressDetail" disabled></el-input>
                </el-form-item>
                <el-form-item label="联系电话" class="selectMB10" :label-width="labelWidth">
                    <el-input  v-model="formInline.linkManMobile" disabled></el-input>
                </el-form-item>
                <el-form-item label="联系人" class="selectMB10" :label-width="labelWidth">
                    <el-input  v-model="formInline.linkMan" disabled></el-input>
                </el-form-item>
            </p>
            <el-form-item label="本次期望到货日期" class="selectMB10" prop="currHopeTime" :label-width="labelWidth130">
                <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.currHopeTime" placeholder="选择日期"  class="selectMB10" @change="updateClick()"></el-date-picker>
            </el-form-item>
        </el-form>

        <!--选择收货库房弹出框-->
        <el-dialog title="请选择库房" :visible.sync="dialogForm1Visible" :lock-scroll="false">
            <el-form :inline="true" :model="storeRoomParm" class="demo-form-inline" style="margin-bottom:20px;border-bottom:1px solid #ccc;">
                <el-form-item label="库房编号" class="selectMB10">
                    <el-input  v-model="storeRoomParm.storeRoomCode" placeholder="输入库房编号"></el-input>
                </el-form-item>
                <el-form-item label="库房名称" class="selectMB10">
                    <el-input  v-model="storeRoomParm.storeRoomName" placeholder="输入库房名称"></el-input>
                </el-form-item>
                <el-form-item class="selectMB10">
                    <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryStoreRoom()" style="margin-right:0px!important;margin-left:5px!important;">查询</el-button>
                </el-form-item>
                <el-form-item class="selectMB10">
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="confirmStoreRoom()" style="margin-right:0px!important;margin-left:5px!important;">确定</el-button>
                </el-form-item>
            </el-form>
            <!--库房列表-->
            <el-table :data="storeRoomData" border style="width: 100%" v-loading.body="loading2">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>

                <el-table-column  label="选" header-align="center" align="center" width="80">
                    <template scope="scope">
                        <el-radio v-model="defaultStoreRoom" :label="scope.row" size="mini">&nbsp;</el-radio>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="storeRoomCode"
                        header-align="center"
                        label="库房编码"
                        width="120" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="storeRoomName"
                        header-align="center"
                        label="库房名称"
                        width="120" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="storeRoomAdress"
                        header-align="center"
                        label="详细地址"
                        width="120" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="shortName"
                        header-align="center"
                        label="收货地简称"
                        width="120" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="linkMan"
                        header-align="center"
                        label="联系人"
                        width="110" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="linkManMobile"
                        header-align="center"
                        label="联系电话"
                        width="110" show-overflow-tooltip>
                </el-table-column>
            </el-table>
            <!--分页-->
            <el-pagination v-if="isPaging" @size-change="handleSizeChange" :page-sizes="[1, 2, 3 , 4, 5]" @current-change="handleCurrentChange" :current-page="pageIndex"  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>

        </el-dialog>
        <!--选择直发地址弹出框-->
        <el-dialog title="请选择直发地址" :visible.sync="dialogForm2Visible" size="300" :lock-scroll="false">
            <el-form :inline="true" :model="shipAddressParm" class="demo-form-inline" style="margin-bottom:20px;border-bottom:1px solid #ccc;" :rules="rules2" ref="shipAddressParm" >
                <el-form-item label="国家">
                    <el-select v-model="shipAddressParm.countryNo" clearable @change="selPro()">
                        <el-option v-for="(country,index) in nationData" :key="index" :label="country.countryName" :value="country.countryNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="省份">
                    <el-select v-model="shipAddressParm.provinceNo" clearable @change="judgeCodeType(0,0,shipAddressParm.provinceNo,0,0)">
                        <el-option v-for="(pro,index) in provinceData" :key="index" :label="pro.provinceName" :value="pro.provinceNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="城市">
                    <el-select v-model="shipAddressParm.cityNo" clearable @change="judgeCodeType(0,1,shipAddressParm.cityNo,0,1)">
                        <el-option v-for="(city,index) in cityData" :key="index" :label="city.cityName" :value="city.cityNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="县/区">
                    <el-select v-model="shipAddressParm.districtNo" clearable>
                        <el-option v-for="(area,index) in areaData" :key="index" :label="area.districtName" :value="area.districtNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="联系人" class="selectMB10">
                    <el-input  v-model="shipAddressParm.linkMan" placeholder="输入联系人信息"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" class="selectMB10">
                    <el-input  v-model="shipAddressParm.linkManMobile" placeholder="输入联系电话信息"></el-input>
                </el-form-item>
                <el-form-item label="详细地址" class="selectMB10">
                    <el-input  v-model="shipAddressParm.adressDetail" placeholder="输入详细地址"></el-input>
                </el-form-item>
                <!--<el-form-item label="收货地简称" class="selectMB10">
                    <el-input  v-model="shipAddressParm.shortName" placeholder="输入收货地简称"></el-input>
                </el-form-item>-->
                <p style="margin-left:440px;">
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryShipAddress()">查询</el-button>
                    </el-form-item>
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="confirmShipAddress()">确定</el-button>
                    </el-form-item>
                </p>

            </el-form>
            <!--直发地址信息列表-->
            <el-table :data="shipAddressData" border style="width: 100%" v-loading.body="loading3">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>

                <el-table-column  label="选" header-align="center" align="center" width="80">
                    <template scope="scope">
                        <el-radio v-model="defaultShipAddress" :label="scope.row" size="mini">&nbsp;</el-radio>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="adressDetail"
                        header-align="center"
                        label="详细地址"
                        width="120" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="shortName"
                        header-align="center"
                        label="收货地简称"
                        width="120" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="linkMan"
                        header-align="center"
                        label="联系人"
                        width="110" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="linkManMobile"
                        header-align="center"
                        label="联系电话"
                        width="110" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="provinceName"
                        header-align="center"
                        label="省份"
                        width="110" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="cityName"
                        header-align="center"
                        label="城市"
                        width="110" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="districtName"
                        header-align="center"
                        label="县/区"
                        width="110" show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        prop="countryName"
                        header-align="center"
                        label="国家"
                        width="110" show-overflow-tooltip>
                </el-table-column>
            </el-table>
            <!--分页-->
            <el-pagination v-if="isPaging2" @size-change="handleSizeChange2" @current-change="handleCurrentChange2" :page-sizes="[1, 2, 3 , 4, 5]" :current-page="pageIndex2" :page-size="pageSize2" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage2" :total="totalNumber2"></el-pagination>

        </el-dialog>
        <!--新增直发地址弹出框-->
        <el-dialog title="新增直发地址" :visible.sync="dialogForm3Visible" :lock-scroll="false">
            <el-form :inline="true" :model="addShipAddressData" class="demo-form-inline" style="margin-bottom:20px;border-bottom:1px solid #ccc;" :rules="rules" ref="addShipAddressData" >
                <el-form-item label="国家" prop="countryNo">
                    <el-select  v-model="addShipAddressData.countryNo" clearable @change="judgeCodeType(1)">
                        <el-option v-for="(country,index) in addShipNationData" :key="index" :label="country.countryName" :value="country.countryNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="省份" prop="provinceNo">
                    <el-select v-model="addShipAddressData.provinceNo" clearable @change="judgeCodeType(2,0,addShipAddressData.provinceNo,1,0)">
                        <el-option v-for="(pro,index) in addShiProvinceData" :key="index" :label="pro.provinceName" :value="pro.provinceNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="城市" prop="cityNo">
                    <el-select v-model="addShipAddressData.cityNo" clearable @change="judgeCodeType(3,1,addShipAddressData.cityNo,1,1)">
                        <el-option v-for="(city,index) in addShiCityData" :key="index" :label="city.cityName" :value="city.cityNo"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="县/区" prop="districtNo">
                    <el-select v-model="addShipAddressData.districtNo" clearable @change="judgeCodeType(4)">
                        <el-option v-for="(area,index) in addShiAreaData" :key="index" :label="area.districtName" :value="area.districtNo"></el-option>
                    </el-select>
                </el-form-item>
                <p style="margin-bottom:12px;">
                    <el-form-item label="详细地址 ： " class="selectMB10" prop="adressDetail">
                        <el-input  v-model="addShipAddressData.adressDetail" placeholder="输入地址" @change="isConClick=false;"></el-input>
                    </el-form-item>
                    <el-form-item label="收货地简称" class="selectMB10" prop="shortName">
                        <el-input  v-model="addShipAddressData.shortName" placeholder="输入地址" @change="isConClick=false;"></el-input>
                    </el-form-item>
                </p>

                <el-form-item label="联系人" class="selectMB10" prop="linkMan">
                    <el-input  v-model="addShipAddressData.linkMan" placeholder="输入联系人信息" @change="isConClick=false;"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" class="selectMB10" prop="linkManMobile">
                    <el-input  v-model="addShipAddressData.linkManMobile" placeholder="输入联系电话信息" @change="isConClick=false;"></el-input>
                </el-form-item>
                <p style="margin-left:240px;">
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS" size="mini" type="danger" :disabled="isConClick" @click="confirmAddShipAddress('addShipAddressData')" style="margin-right:0px!important;margin-left:10px!important;">确定</el-button>
                    </el-form-item>
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="cancelAddShipAddress()" style="margin-right:0px!important;margin-left:10px!important;">取消</el-button>
                    </el-form-item>
                </p>

            </el-form>
        </el-dialog>
        <!-- 备件信息-->
        <label>备件信息</label>
        <el-table ref="clearSel" :data="materiaData" border style="margin-top:16px;width: 100%;" v-loading.body="loading"  @selection-change="handleSelectionChange">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column type="selection" align="center"  width="40"></el-table-column>
            <el-table-column
                    prop="materialCode"
                    header-align="center"
                    label="备件编码"
                    width="130" show-overflow-tooltip>
            </el-table-column>
            <el-table-column
                    prop="materialName"
                    header-align="center"
                    label="备件名称"
                    width="130" show-overflow-tooltip>
            </el-table-column>
            <el-table-column
                    prop="standard"
                    header-align="center"
                    label="规格"
                    width="120" show-overflow-tooltip>
            </el-table-column>
            <el-table-column
                    prop="materialUnit"
                    header-align="center"
                    label="计量单位"
                    width="130" show-overflow-tooltip>
            </el-table-column>
            <el-table-column
                    prop="materialQuantity"
                    header-align="center"
                    label="采购数量"
                    width="130">
            </el-table-column>
            <el-table-column
                    prop="noticeQuantity"
                    header-align="center"
                    label="已通知数量"
                    width="130">
            </el-table-column>
            <!--需要填写的一列-->
            <el-table-column prop="currQuantity" label="本次通知数量" header-align="center" width="180">
                <template scope="scope">
                    <el-input size="mini" v-model.number="scope.row.currQuantity" placeholder="请输入本次通知数量"  @change="inputCurrQuantity(scope.$index, scope.row)"></el-input>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                labelWidth:"80px",
                labelWidth100:"100px",
                labelWidth130:"130px",
                // 查询表单
                formInline:{
                    poCode:"",
                    shipRequestNo:"",
                    shipRequestUserName:"",
                    createTime:"",
                    storeRoomNo:"",
                    storeRoomAdress:"",//库房地址
                    shipAdressNo:"",
                    shipAdress:"",//直发地址
                    adressDetail:"",//直发地或者库房地址，谁存在指谁
                    shortName:"",//收货地址简称
                    linkManMobile:"",
                    linkMan:"",
                    legalPersonCode:"",
                    currHopeTime:"",
                    partnerCode:"",//供应商编码
                    partnerName:"",//供应商名称
                    procurementCategory:"",//采购类别，暂存
                    emergencyDegree:"",//紧急程度，暂存
                    legalPersonName:"",//采购单位法人名称，暂存
                    amount:"",//PO采购数量，暂存
                    hopeTime:""//po到货时间
                },
                //库房需查询条件数据
                storeRoomParm:{
                    storeRoomCode:"",//库房编码
                    storeRoomName:""//库房名称
                },
                //直发地查询条件数据
                shipAddressParm:{
                    countryNo:"",
                    countryName:"",
                    provinceNo:"",
                    provinceName:"",
                    cityNo:"",
                    cityName:"",
                    districtName:"",
                    shortName:"",
                    districtNo:"",
                    linkMan:"",
                    linkManMobile:"",
                    adressDetail:"",
                    codeType:"",
                    code:""
                },
                //新增直发地址表单
                addShipAddressData:{
                    countryNo:"",
                    countryName:"",
                    provinceNo:"",
                    provinceName:"",
                    cityNo:"",
                    cityName:"",
                    districtNo:"",
                    districtName:"",
                    adressDetail:"",
                    shortName:"",
                    linkMan:"",
                    linkManMobile:""
                },
                isNum:false,//验证是否是数字
                isNew:"",//是否是直发地
                suFlag:"",//0保存，1提交
                smFlag:"",//判断是否是修改，0 不是修改 ; 1 是修改
                checked:false,//复选框
                isClick:false,//判断保存是否可以点击
                isConClick:false,//判断新增确定是否可点击
                dialogForm1Visible: false,//选择库房弹出框
                dialogForm2Visible: false,//选择直发地址弹出框
                dialogForm3Visible: false,//新增直发地址弹出框

                disabled:false,
                shipAddressData:[],//直发地址数据
                nationData:[],//国家列表
                addShipNationData:[],//新增发货地国家列表
                provinceData:[],//省列表
                addShiProvinceData:[],//新增发货地省列表
                cityData:[],//市列表
                addShiCityData:[],//新增市列表
                areaData:[],//县/区列表
                addShiAreaData:[],//新增县/区列表
                materiaData: [],// 备件信息表
                selMateriaData:[],//被选中需要保存或提交的数据
                storeRoomData:[],//库房列表数据
                defaultStoreRoom:{},//选择库房
                defaultShipAddress:{},//选择直发地址

                //加载loading
                loading:false,
                loading2:false,
                loading3:false,

                // 库房分页
                pageIndex:1,    //当前页（必传）
                pageSize :5,   //每页多少条
                totalNumber: 20,
                totalPage:2,
                isPaging:false,
                // 直发地分页
                pageIndex2:1,    //当前页（必传）
                pageSize2 :5,   //每页多少条
                totalNumber2: 20,
                totalPage2:2,
                isPaging2:false,

                //验证
                rules: {
                    currHopeTime: [
                        { type: 'date', required: true, message: '期望到货日期不能为空', trigger: 'change' }
                    ],
                    countryNo:[
                        { required: true, message: '请选择国家', trigger: 'change' }
                    ],
                    provinceNo:[
                        { required: true, message: '请选择省份', trigger: 'change' }
                    ],
                    cityNo:[
                        { required: true, message: '请选择城市', trigger: 'change' }
                    ],
                    districtNo:[
                        { required: true, message: '请选择县/区', trigger: 'change' }
                    ],
                    adressDetail:[
                        { required: true, message: '请填写详细地址', trigger: 'change' },
                        { max: 100, message: '长度最大为 100 个字符', trigger: 'blur' }
                    ],
                    shortName:[
                        {required: true, message: '请填写收货地址详情', trigger: 'change' },
                        { max: 50, message: '长度最大为 50 个字符', trigger: 'blur' }
                    ],
                    linkMan:[
                        { required: true, message: '请填写联系人', trigger: 'change' },
                        { max: 50, message: '长度最大为 50 个字符', trigger: 'blur' }
                    ],
                    linkManMobile:[
                        { required: true, message: '请填写联系方式', trigger: 'change' },
                        { max: 50, message: '长度最大为 50 个字符', trigger: 'blur' }
                    ]
                },
                rules2: {
                    adressDetail:[
                        { max: 100, message: '长度最大为 100 个字符', trigger: 'change' }
                    ],
                    linkMan:[
                        { max: 50, message: '长度最大为 50 个字符', trigger: 'change' }
                    ],
                    linkManMobile:[
                        { max: 50, message: '长度最大为 50 个字符', trigger: 'change' }
                    ]
                },
                //查询禁用
                selectDisabled:false
            };
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'CreateNoticeSheet');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            _this.smFlag=_this.$route.query.smFlag;//传参,判断是新建还是修改
            _this.formInline.shipRequestNo=_this.$route.query.shipRequestNo;//传参,判断是新建还是修改
            _this.formInline.poCode=_this.$route.query.poCode;//从通知发货传参
            _this.isBuildOrUpdate();//根据是新建还是修改调取不同的接口
        },
        methods: {
            selectAll(){
                var _this=this;
                for(var i=0;i<_this.materiaData.length;i++){
                    _this.$refs.clearSel.toggleRowSelection(_this.materiaData[i]);//默认全选
                }
            },
            //判断是新建还是修改获取相应的页面信息
            isBuildOrUpdate(){
                var _this=this;
                if(_this.smFlag=="0"){
                    //新建
                    _this.getBuildPoInfor();//新建获取表头和备件信息表
                }else if(_this.smFlag=="1"){
                    //修改
                    _this.getUpdatePoInfor();//修改获取表头和备件信息表
                }
            },
            //新建根据PO编码传参获取到相应的数据信息
            getBuildPoInfor(){
                var _this=this;
                _this.loading=true;
                //console.log(_this.formInline.poCode)
                /*var tmp={
                 poCode:_this.formInline.poCode  // PO编号
                 };*/
                $.ajax({
                    type: 'GET',
                    url: _this.procurement_service+"shipRequest/findShipReqMaterList?poCode="+_this.formInline.poCode,
                    cache: false,
                    //data:JSON.stringify(tmp),
                    //dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        //console.log(data)
                        if (data.success) {
                        _this.loading=false;
                        _this.materiaData=data.data.dataList;//备件信息
                        // console.log(_this.materiaData);
                        _this.formInline.poCode=data.data.poCode;//po单号
                        _this.formInline.shipRequestNo=data.data.shipRequestNo;//通知送货单号
                        _this.formInline.shipRequestUserName=data.data.shipRequestUserName;//制单人
                        _this.formInline.legalPersonCode=data.data.legalPersonCode;//采购单位
                        _this.formInline.createTime=data.data.createTime;//获取制单日期
                        _this.formInline.currHopeTime=data.data.currHopeTime;//本次期望到货时间
                        _this.formInline.procurementCategory=data.data.procurementCategory;//采购类别
                        _this.formInline.emergencyDegree=data.data.emergencyDegree;//紧急程度
                        _this.formInline.partnerCode=data.data.partnerCode;//供应商编码
                        _this.formInline.partnerName=data.data.partnerName;//供应商名称
                        _this.formInline.legalPersonName=data.data.legalPersonName;//采购单位法人名称
                        _this.formInline.amount=data.data.amount;//PO采购数量
                        _this.formInline.hopeTime=data.data.hopeTime;//PO期望到货时间
                        _this.$nextTick(function(){
                            _this.selectAll();
                        })
                        }else{
                         _this.common.errorTip(data.errorMessage);
                         }
                    }
                });

            },
            //修改根据shipRequestNo传参获取到相应的数据信息
            getUpdatePoInfor(){
                var _this=this;
                _this.loading=true;
                $.ajax({
                    type: 'GET',
                    url: _this.procurement_service+"shipRequest/getToUpdateInfo?shipRequestNo="+_this.formInline.shipRequestNo,
                    cache: false,
                    //data:JSON.stringify(tmp),
                    //dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        //console.log("aaaaaaaa")
                        if (data.success) {
                            _this.loading=false;
                            _this.materiaData=data.data.dataList;//备件信息
                            // console.log(_this.materiaData);
                            _this.formInline.poCode=data.data.poCode;//po编码
                            _this.formInline.shipRequestNo=data.data.shipRequestNo;//通知送货单号
                            _this.formInline.shipRequestUserName=data.data.shipRequestUserName;//制单人
                            _this.formInline.legalPersonCode=data.data.legalPersonCode;//采购单位
                            _this.formInline.createTime=data.data.createTime;//获取制单日期
                            /* _this.formInline.storeRoomNo=data.shipRequestStoreNo;//获取库房编码
                             _this.formInline.shipAdressNo=data.shipAdressNo;//获取直发地址编码*/
                            _this.formInline.shortName=data.data.shortName;//获取收货地简称
                            _this.formInline.adressDetail=data.data.adressDetail;//获取地址
                            _this.formInline.linkMan=data.data.linkMan;//获取联系人
                            _this.formInline.linkManMobile=data.data.linkManMobile;//获取联系方式
                            //将获取的日期字符串转换成日期对象
                            _this.formInline.currHopeTime=new Date(data.data.currHopeTime);//获取期望到货日期

                            _this.$nextTick(function(){
                                _this.selectAll();
                            })

                            //console.log(_this.formInline.currHopeTime)
                            //通过判断直发地址和库房地址的编码，选择地址位置
                            /* if(data.shipRequestStoreNo!="" || data.shipRequestStoreNo!=null){
                             _this.formInline.storeRoomAdress=data.adressDetail;//获取库房地址
                             }else{
                             _this.formInline.adressDetail=data.adressDetail;//获取直发地址
                             }*/

                        } else{
                            _this.common.errorTip(data.errorMessage);
                         }
                    }
                });
            },
            //验证选中且本次发货数量大于0
            validSendData(){
                var _this=this;
                var arr=_this.selMateriaData;
                if(arr.length>0){
                    for(var i=0;i<arr.length;i++){
                        if(/^(\-?)(\d+)$/.test(arr[i].currQuantity)){
                            if(arr[i].currQuantity<=0){
                                //有一个小于等于0的就返回false
                                return false;
                            }

                        }else{
                            _this.isNum=false;
                            _this.common.errorTip("请填入数字");
                            return false;
                        }

                    }
                    //验证都通过的返回true
                    _this.isNum=true;
                    return true;
                }else{
                    //没有选中的返回false
                    return false;
                }

            },
            //判断是直发地址还是库房地址------合二为一了
            /* shipOrStore(){
             var _this=this;
             if(_this.formInline.storeRoomAdress!=null || _this.formInline.storeRoomAdress!=""){
             _this.formInline.adressDetail=_this.formInline.storeRoomAdress;
             }else if(_this.formInline.shipAdress!=null || _this.formInline.shipAdress!=""){
             _this.formInline.adressDetail=_this.formInline.shipAdress;
             }
             },*/
            //保存
            saveShipReqInfo(formName){
                var _this=this;
                _this.suFlag="btnSave";
                _this.validBeforeSave(formName);
                _this.isClick=true;
            },
            //提交
            commitShipReqInfo(formName){
                var _this=this;
                _this.suFlag="btnSubmit";
                _this.validBeforeSave(formName);
                _this.isClick=true;
            },
            updateClick(){
                var _this=this;
                _this.isClick=false;
            },
            //保存提交前的验证
            validBeforeSave(formName){
                var _this=this;
                var validSend=_this.validSendData(); //验证本次发货数量
                // var sendAdress=_this.shipOrStore();//验证发货地址
                //验证期望到货日期不能为空
                _this.$refs[formName].validate((valid) => {
                    //console.log(valid)
                    if (valid) {

                        if(validSend){
                            if(_this.isNum){
                                if(_this.formInline.adressDetail!=""){
                                    _this.saveOrUpdateShipReqInfo();//验证全部成功后保存或提交
                                    //console.log("保存成功")
                                }else{
                                    _this.isClick=false;
                                    _this.common.errorTip("请选择收货库房或者直发地址");
                                }
                            }else{
                                _this.isClick=false;
                                _this.common.errorTip("本次发货数量必须是数字");
                            }
                        }else{
                            _this.isClick=false;
                            _this.common.errorTip("请选中要提交的数据并且本次发货数量大于0");
                        }


                    } else {
                        // console.log('error submit!!');
                        _this.isClick=false;
                        console.log(_this.isClick)
                        return false;
                    }
                });
            },
            //将填写的本次送货数量加入到对应的行中
            inputCurrQuantity(index,row){
                var _this=this;
                _this.isClick=false;
                //做参数判断，只允许填入数字
                if(/^(\-?)(\d+)$/.test(row.currQuantity)){
                    //_this.isNum=true;
                    _this.materiaData[index].currQuantity=row.currQuantity;
                }else{
                    // _this.isNum=false;
                    _this.common.errorTip("请填入数字");
                }
            },
            // selection-change	当选择项发生变化时会触发该事件
            handleSelectionChange(val){
                var _this=this;
                _this.selMateriaData=val;
                _this.isClick=false;
            },
            //处理参数，删去多余的需要保存和提交的参数
            dealParms(){
                var _this=this;
                var parms=_this.selMateriaData;
                var newParms=[];
                for(var i=0;i<parms.length;i++){
                    var parmsObj={};
                    parmsObj.materialCode=parms[i].materialCode;
                    parmsObj.materialName=parms[i].materialName;
                    parmsObj.standard=parms[i].standard;
                    parmsObj.materialUnit=parms[i].materialUnit;
                    parmsObj.currQuantity=parms[i].currQuantity;
                    parmsObj.shipRequestDetailId=parms[i].shipRequestDetailId;
                    newParms.push(parmsObj);
                }
                return newParms
            },
            //通知发货的保存和提交方法
            saveOrUpdateShipReqInfo(){
                var _this=this;
                //将日期变为字符串
                var currHopeTime=_this.formInline.currHopeTime.getFullYear()+"-"+(_this.formInline.currHopeTime.getMonth()+1)+"-"+_this.formInline.currHopeTime.getDate();
                var materList=_this.dealParms();
                var tmp={};
                //判断是新建还是修改，提交不同的参数
                if(_this.smFlag=="0"){
                    //新建
                    tmp={
                        suFlag:_this.suFlag,//btnSave代表保存 ; btnSubmit代表提交
                        smFlag:_this.smFlag,//0 不是修改 ; 1 是修改
                        poCode:_this.formInline.poCode,//po编号
                        shipRequestNo:_this.formInline.shipRequestNo,//发货单号
                        shipRequestUserName:_this.formInline.shipRequestUserName,//制单人
                        createTime:_this.formInline.createTime,//制单日期
                        shipRequestStoreNo:_this.formInline.storeRoomNo,//库房编号
                        shipAdressNo:_this.formInline.shipAdressNo,//发货地址编号
                        linkMan:_this.formInline.linkMan,//联系人
                        linkManMobile:_this.formInline.linkManMobile,//联系方式

                        adressDetail:_this.formInline.adressDetail,//详细地址
                        shortName:_this.formInline.shortName,//收货地简称
                        hopeTime:_this.formInline.hopeTime,//到货时间
                        procurementCategory:_this.formInline.procurementCategory,//采购类别
                        emergencyDegree:_this.formInline.emergencyDegree,//紧急程度
                        partnerCode:_this.formInline.partnerCode,//供应商编码
                        partnerName:_this.formInline.partnerName,//供应商名称
                        legalPersonCode:_this.formInline.legalPersonCode,//订单采购单位
                        legalPersonName:_this.formInline.legalPersonName,//订单采购单位法人名称
                        amount:_this.formInline.amount,//PO采购数量

                        currHopeTime:currHopeTime,//本次期望到货时间
                        materList:materList,
                    }
                }else if(_this.smFlag=="1"){
                    //修改
                    tmp={
                        suFlag:_this.suFlag,//btnSave代表保存 ; btnSubmit代表提交
                        smFlag:_this.smFlag,//0 不是修改 ; 1 是修改
                        poCode:_this.formInline.poCode,//po编号
                        shipRequestNo:_this.formInline.shipRequestNo,//发货单号
                        shipRequestUserName:_this.formInline.shipRequestUserName,//制单人
                        createTime:_this.formInline.createTime,//制单日期
                        shipRequestStoreNo:_this.formInline.storeRoomNo,//库房编号
                        shipAdressNo:_this.formInline.shipAdressNo,//发货地址编号
                        linkMan:_this.formInline.linkMan,//联系人
                        linkManMobile:_this.formInline.linkManMobile,//联系方式

                        adressDetail:_this.formInline.adressDetail,//详细地址
                        shortName:_this.formInline.shortName,//收货地简称
                        /*hopeTime:_this.formInline.hopeTime,//到货时间
                         procurementCategory:_this.formInline.procurementCategory,//采购类别
                         emergencyDegree:_this.formInline.emergencyDegree,//紧急程度
                         partnerCode:_this.formInline.partnerCode,//供应商编码
                         partnerName:_this.formInline.partnerName,//供应商名称
                         legalPersonCode:_this.formInline.legalPersonCode,//订单采购单位
                         legalPersonName:_this.formInline.legalPersonName,//订单采购单位法人名称
                         amount:_this.formInline.amount,//PO采购数量*/

                        currHopeTime:currHopeTime,//本次期望到货时间
                        materList:materList,
                    }
                }
                //console.log(JSON.stringify(tmp));
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service+"shipRequest/saveOrUpdateShipReqInfo",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        //console.log(tmp)
                        if(data.success){
                            _this.common.successTip("成功");
                            window.location.href="#NoticeDeliverySheet";//跳转页面
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }

                    }
                });
            },
            //------选择收货库房点击
            selectStoreRoom(){
                var _this=this;
                _this.storeRoomParm.storeRoomCode="";//清空
                _this.storeRoomParm.storeRoomName="";
                _this.dialogForm1Visible=true;
                _this.queryStoreRoom();
                _this.isClick=false;
            },
            //收货库房查询
            queryStoreRoom(){
                var _this=this;
                _this.loading2=true;
                var tmp={
                    legalPersonCode:_this.formInline.legalPersonCode,//采购单位
                    storeRoomCode:_this.storeRoomParm.storeRoomCode,//库房编号
                    storeRoomName:_this.storeRoomParm.storeRoomName,  // 库房名称
                    pageIndex:_this.pageIndex,
                    pageSize:_this.pageSize
                };
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service +"storeRoom/findStoreRoomList",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        //  if (data.success) {
                        //console.log(data);
                        _this.loading2=false;
                        _this.isPaging=true;
                        _this.totalPage=data.data.totalPage;
                        _this.totalNumber=data.data.totalNumber;
                        _this.storeRoomData=data.data.dataList;//收货库房数据



                        /* }else{
                         _this.common.errorTip(data.errorMessage)
                         }*/
                    }
                });
            },
            //收货库房确定
            confirmStoreRoom(){
                var _this=this;
                //加一层判断，必须选中才能确定
                if(JSON.stringify(_this.defaultStoreRoom)!="{}"){
                    _this.formInline.storeRoomNo=_this.defaultStoreRoom.storeRoomCode;
                    _this.formInline.storeRoomAdress=_this.defaultStoreRoom.storeRoomAdress;
                    _this.formInline.linkMan=_this.defaultStoreRoom.linkMan;
                    _this.formInline.linkManMobile=_this.defaultStoreRoom.linkManMobile;
                    _this.formInline.shipAdress="";
                    _this.formInline.adressDetail=_this.defaultStoreRoom.storeRoomAdress;//库房填入
                    _this.formInline.shortName=_this.defaultStoreRoom.shortName;//填简称
                    // console.log(_this.formInline.linkMan)
                    _this.dialogForm1Visible=false;
                }else{
                    _this.common.errorTip("请选中你要选择的收货库房");
                }

            },
            //------选择直发地址点击
            selectShipAddress(){
                var _this=this;
                //清空
                _this.shipAddressParm.countryNo="",
                _this.shipAddressParm.provinceNo="",
                _this.shipAddressParm.cityNo="",
                _this.shipAddressParm.districtNo="",
                _this.shipAddressParm.adressDetail="",
                _this.shipAddressParm.linkMan="",
                _this.shipAddressParm.linkManMobile="",

                _this.dialogForm2Visible=true;
                _this.loading3=true;
                _this.queryShipAddress();
                _this.selectShipAddressNation();
                _this.isClick=false;
            },
            //直发地址国家下拉框查询
            selectShipAddressNation(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"baseAddress/getCountryProList",
                    cache: false,
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        _this.nationData=data.data;//国家列表
                    }
                });
            },
            selPro(){
                var _this=this;
                _this.selectShipAddressPro();
            },
            //获取省列表
            selectShipAddressPro(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"baseAddress/getProList?countryNo="+_this.shipAddressParm.countryNo,
                    cache: false,
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        _this.provinceData=data.data;//省列表
                    }
                });
            },
            //直发地址查询
            queryShipAddress(){
                var _this=this;
                _this.loading3=true;
                var tmp={
                    legalPersonCode:_this.formInline.legalPersonCode,//采购单位
                    countryNo:_this.shipAddressParm.countryNo,
                    provinceNo:_this.shipAddressParm.provinceNo,
                    cityNo:_this.shipAddressParm.cityNo,
                    districtNo:_this.shipAddressParm.districtNo,
                    adressDetail:_this.shipAddressParm.adressDetail,
                    linkMan:_this.shipAddressParm.linkMan,
                    linkManMobile:_this.shipAddressParm.linkManMobile,
                    pageIndex:_this.pageIndex2,
                    pageSize:_this.pageSize2
                };
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"shipAdressInfo/getShipAdressList",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        // if (data.success) {
                        _this.loading3=false;
                        _this.isPaging2=true;
                        _this.totalPage2=data.data.totalPage;
                        _this.totalNumber2=data.data.totalNumber;
                        _this.shipAddressData=data.data.dataList;//直发库房数据
                        _this.selectDisabled=false;
                    }
                });
            },
            //直发地址确定
            confirmShipAddress(){
                var _this=this;
                //加一层判断，必须选中才能确定
                if(JSON.stringify(_this.defaultShipAddress)!="{}"){
                    _this.formInline.shipAdressNo=_this.defaultShipAddress.shipAdressNo;
                    _this.formInline.adressDetail=_this.defaultShipAddress.adressDetail;
                    _this.formInline.shortName=_this.defaultShipAddress.shortName;
                    _this.formInline.linkMan=_this.defaultShipAddress.linkMan;
                    _this.formInline.linkManMobile=_this.defaultShipAddress.linkManMobile;
                    _this.formInline.storeRoomAdress="";
                    _this.dialogForm2Visible=false;
                }else{
                    _this.common.errorTip("请选中你要选择的送货地址");
                }

            },
            //地区change事件获取地区编码和名称进行传参      //isNew代表是否是新增直发地列表，0代表不是，1代表是
            // clearAll代表重新选择省市区时，将之前的选择清空
            judgeCodeType(changeType,type,code,isNew,clearAll){
                // console.log(type,code);
                var _this=this;
                //
                if(clearAll==0){
                    if(changeType==2){
                        _this.addShipAddressData.cityNo="";
                        _this.addShipAddressData.districtNo="";
                    }else{
                        _this.shipAddressParm.cityNo="";
                        _this.shipAddressParm.districtNo="";
                    }

                }else if(clearAll==1){
                    if(changeType==3){
                        _this.addShipAddressData.districtNo="";
                    }else{
                        _this.shipAddressParm.districtNo="";
                    }
                }
                if(changeType==1){
                     _this.isConClick=false;
                    //获取当前的国家名称
                    for(var i=0;i<_this.addShipNationData.length;i++){
                        if(_this.addShipAddressData.countryNo==_this.addShipNationData[i].countryNo){
                            _this.addShipAddressPro();
                            _this.addShipAddressData.countryName=_this.addShipNationData[i].countryName;
                        }
                    }
                }else if(changeType==2){
                    _this.isConClick=false;
                    //获取当前的省名称
                    for(var i=0;i<_this.addShiProvinceData.length;i++){
                        if(_this.addShipAddressData.provinceNo==_this.addShiProvinceData[i].provinceNo){
                            _this.addShipAddressData.provinceName=_this.addShiProvinceData[i].provinceName;
                        }
                    }
                }else if(changeType==3){
                    _this.isConClick=false;
                    //获取当前的市名称
                    for(var i=0;i<_this.addShiCityData.length;i++){
                        if(_this.addShipAddressData.cityNo==_this.addShiCityData[i].cityNo){
                            _this.addShipAddressData.cityName=_this.addShiCityData[i].cityName;
                        }
                    }
                }else if(changeType==4){
                    _this.isConClick=false;
                    //获取当前的县区名称
                    for(var i=0;i<_this.addShiAreaData.length;i++){
                        if(_this.addShipAddressData.districtNo==_this.addShiAreaData[i].districtNo){
                            _this.addShipAddressData.districtName=_this.addShiAreaData[i].districtName;
                        }
                    }
                }
                //console.log(_this.addShipAddressData)

                //判断获取市还是区//
                if(code){
                    //console.log(type,code,isNew)
                    _this.shipAddressParm.codeType=type;
                    _this.shipAddressParm.code=code;
                    _this.isNew=isNew;
                    _this.getAdressInfoList();
                }

            },
            //省市区联动查询//
            getAdressInfoList(){
                var _this=this;
                var tmp={
                    //countryNo:"001",//国家编号,只有中国
                    countryNo:_this.shipAddressParm.countryNo || _this.addShipAddressData.countryNo,//国家编号,只有中国
                    code:_this.shipAddressParm.code,//省或市的编码
                    codeType:_this.shipAddressParm.codeType,//调取类型，0代表获取市，1代表获取区

                };
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"baseAddress/getAdressInfoList",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        // if (data.success) {
                        if(_this.shipAddressParm.codeType==1){
                            //获取区
                            if(_this.isNew==0){
                                _this.areaData=data.data;
                            }else if(_this.isNew==1){
                                _this.addShiAreaData=data.data;
                            }

                        }else if(_this.shipAddressParm.codeType==0){
                            //获取市
                            if(_this.isNew==0){
                                _this.cityData=data.data;
                            }else if(_this.isNew==1){
                                _this.addShiCityData=data.data;
                            }

                        }
                        /* }else{
                         _this.common.errorTip(data.errorMessage)
                         }*/
                    }
                });
            },
            //------新增直发地址点击
            addShipAddress(){
                var _this=this;
                _this.addShipAddressData.countryNo="",
                _this.addShipAddressData.countryName="",
                _this.addShipAddressData.provinceNo="",
                _this.addShipAddressData.provinceName="",
                _this.addShipAddressData.cityNo="",
                _this.addShipAddressData.cityName="",
                _this.addShipAddressData.districtNo="",
                _this.addShipAddressData.districtName="",
                _this.addShipAddressData.adressDetail="",
                _this.addShipAddressData.shortName="",
                _this.addShipAddressData.linkMan="",
                _this.addShipAddressData.linkManMobile="",
                _this.dialogForm3Visible=true;
                _this.addShipAddressNation();
                _this.isClick=false;
            },
             //获取新增国家
             addShipAddressNation(){
             var _this=this;
             $.ajax({
                 type: 'GET',
                 url: _this.metadata_service+"baseAddress/getCountryProList",
                 cache: false,
                 dataType:'JSON',
                 contentType: "application/json;charset=utf-8",
                 success: function (data) {
                     _this.addShipNationData=data.data;//国家列表
                     //_this.addShipAddressPro();
                 }
             });
             },
             //获取新增省
             addShipAddressPro(){
             var _this=this;
             $.ajax({
                 type: 'GET',
                 url: _this.metadata_service+"baseAddress/getProList?countryNo="+_this.addShipAddressData.countryNo,
                 cache: false,
                 dataType:'JSON',
                 contentType: "application/json;charset=utf-8",
                 success: function (data) {
                     _this.addShiProvinceData=data.data;//省列表
                 }
             });
             },
            //新增直发地址确定
            confirmAddShipAddress(formName){
                var _this=this;
                _this.isConClick=true;
                //验证
                _this.$refs[formName].validate((valid) => {
                    //console.log(valid)
                    if (valid) {
                        var tmp={
                            legalPersonCode:_this.formInline.legalPersonCode,
                            countryNo:_this.addShipAddressData.countryNo,
                            countryName:_this.addShipAddressData.countryName,
                            provinceNo:_this.addShipAddressData.provinceNo,
                            provinceName:_this.addShipAddressData.provinceName,
                            cityNo:_this.addShipAddressData.cityNo,
                            cityName:_this.addShipAddressData.cityName,
                            districtNo:_this.addShipAddressData.districtNo,
                            districtName:_this.addShipAddressData.districtName,
                            adressDetail:_this.addShipAddressData.adressDetail,
                            shortName:_this.addShipAddressData.shortName,
                            linkMan:_this.addShipAddressData.linkMan,
                            linkManMobile:_this.addShipAddressData.linkManMobile,
                        };
                        //console.log(JSON.stringify(tmp))
                        //setTimeout(function(){
                            $.ajax({
                                type: 'POST',
                                url: _this.metadata_service+"shipAdressInfo/saveShipAdress",
                                cache: false,
                                data:JSON.stringify(tmp),
                                dataType:'JSON',
                                contentType: "application/json;charset=utf-8",
                                success: function (data) {
                                    if (data.success) {
                                        _this.dialogForm3Visible=false;
                                        //回显到页面;
                                        _this.formInline.adressDetail=_this.addShipAddressData.adressDetail;
                                        _this.formInline.shortName=_this.addShipAddressData.shortName;
                                        _this.formInline.linkMan=_this.addShipAddressData.linkMan
                                        _this.formInline.linkManMobile=_this.addShipAddressData.linkManMobile;
                                        _this.common.successTip("新增发货地址成功");
                                    }else{
                                        _this.common.errorTip(data.errorMessage)
                                    }
                                }
                            });
                       // },1000)

                    } else {
                        // console.log('error submit!!');
                        return false;
                    }
                });

            },
            //新增直发地址取消
            cancelAddShipAddress(){
                var _this=this;
                _this.dialogForm3Visible=false;
            },
            //   库房分页
            handleSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                var _this=this;
                _this.pageSize=val;
                _this.queryStoreRoom();

            },
            //库房点击页码分页查询点击事件
            handleCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this=this;
                _this.pageIndex=val;
                _this.queryStoreRoom();
            },
            //   直发地址分页
            handleSizeChange2(val) {
                // console.log(`每页 ${val} 条`);
                var _this=this;
                _this.pageSize2=val;
                _this.queryShipAddress();

            },
            //直发地址点击页码分页查询点击事件
            handleCurrentChange2(val) {
                // console.log(`当前页: ${val}`);
                var _this=this;
                _this.pageIndex2=val;
                _this.queryShipAddress();
            },
            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }
        }
    }
</script>

